package Day06;

import java.util.LinkedList;
import java.util.Queue;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-09-17
 * Time: 23:23
 * To BE A Better Person-2020-3-2
 */
public class TestDemo2 {
    public static int StrToInt(String str) {
        if(str==null) return 0;
        int[] arr=new int[str.length()];
        int index=0;
        char f = 0;
        int sum=0;
        if (str.charAt(0) == '+' || str.charAt(0) == '-'){
            index=1;
            f=str.charAt(0);
        }
        for (int i = index; i < str.length(); i++) {
            if(str.charAt(i) >= 48 && str.charAt(i) <= 57){
                int temp=((int) str.charAt(i))-48;
                arr[i-index]=temp;
            }else{
                    return 0;
            }
        }
        //将数组中的数字转化为数字
        for (int i = 0; i < arr.length-index; i++) {
            sum+=arr[i]*Math.pow(10, arr.length-index-i-1);
        }
        if(f == '-'){
            return -sum;
        }
        return sum;

    }
    public static void main(String[] args) {
        String s="";
        int ret=StrToInt(s);
        System.out.println(ret);
    }
}
